#coding=utf-8
import urllib, urllib2, time

#RECEIVER = 'jay@email-portal.appspotmail.com'
RECEIVER = 'xiaojay@gmail.com'
#RECEIVER = 'feynman1983@163.com'
#RECEIVER = 'nbujiangjie@yahoo.cn'

def print_red(s):
  print '\033[0;31;48m%s\033[0m'%s  
  
import os, sys, subprocess
SCRIPT_ROOT = os.path.realpath(os.path.dirname(__file__))
PACKAGE_PATH = os.path.normpath(os.path.join(SCRIPT_ROOT, '../../'))
sys.path.append(PACKAGE_PATH)

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'emailserver_manager.settings'
from emailserver_manager.host.models import App, Account

apps = App.objects.order_by('created_at').all()
for app in apps:
  print_red(app.name)
  urllib.urlopen('http://%s.appspot.com/send_mail?email=%s'%(app.name, RECEIVER))
  print_red(app.name)
  time.sleep(1)
